import numpy as np 
def my_weight_loss(pred, y_true):
    y = y_true.get_label()
    p = pred
    # print('p  ',p)
    # print('y  ',y)
    k1 = (abs(y)<=0.05).astype(int) * 0.5
    k2 = (abs(y)>0.05).astype(int) * 1
    k = k1 + k2
    n = len(y)
    grad = np.power(k,2) * (y-p)*2/n
    hess = np.power(k,2)*2/n
    # print('grad  ',grad)
    # print('hess  ',hess)
    return grad, hess

def my_weight_metric(preds, y_true):
    y = y_true.get_label()
    p = preds
    k1 = (abs(y)<=0.05).astype(int) * 0.5
    k2 = (abs(y)>0.05).astype(int) * 1
    k = k1 + k2
    n = len(y)

    ll = np.sum(np.power(k*(p-y), 2))/n

    is_higher_better = False
    return 'my_weight_metric', ll, is_higher_better